#include <cstdlib>
#include "graph.h"
#include "utils.h"

int main(int argc, char **argv)
{
	if (argc != 4)
	{
		std::cout << "Usage: exe filename algorithm data_structure\n";
		return EXIT_SUCCESS;
	}

	int iType = toInt(argv[2]);
	int sType = toInt(argv[3]);

	Graph::Algorithm type;

	if (iType == 1)
	{
		if (sType == 0) type = Graph::prim_heap;
		else if (sType == 1) type = Graph::prim_unordered;
		else type = Graph::prim_stdqueue;
	}
	else
	{
		if (sType == 0) type = Graph::kruskal_heapsort;
		else if (sType == 1) type = Graph::kruskal_mergesort;
		else if (sType == 2) type = Graph::kruskal_bubblesort;
		else type = Graph::kruskal_stdsort;
	}

	// This would be a more appropriate use of the tokenizer, as splitting streams
	// based on tokens to get part of a string can be tricky if multiple different
	// character tokens are required (stream functions only accept a single character
	// token)
	std::string plName = argv[1];
	std::vector<std::string> t = tokenize(plName, "-.");
	int size = toInt(t.at(t.size() - 2));

	std::stringstream mss;
	mss << "mst-" << size << ".svg";
	std::string mstName = mss.str();

	Graph graph;
	graph.loadPoints(plName);
	graph.calculateMST(type);
	graph.saveMST(mstName);

	return EXIT_SUCCESS;
}
